1
general::
Also, within an inch of. Very close to, within a narrow margin of, as in We were within an ace of calling you, but we'd lost your phone number, or We were within an inch of buying tickets for that concert. The first term refers to the ace of dice, that is, the one pip on a die. The lowest number one can throw with a pair of dice is two (two aces), a throw that is within an ace of one. The term began to be used for other kinds of near miss by about 1700.
American Heritage Idioms
2
general::
Phrase(s): within an ace of (doing) something [and] within a hair(’s breadth) of something
very close to doing something. • I came within an ace of getting into an accident. • We were within an ace of beating the all-time record. • We were within a hair’s breadth of beating the all-time record.
McGrawhill's American Idioms And Phrasal Verbs